<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------

namespace app\common\extend;

class Cxforms{
    //  解析字段
    function rarfield($data,$fields = ''){
        $field = $data['field_db'];
        $list = array();
        if(!empty($field) && isset($field)){
            foreach ($field as $v){
                $list[] = $this->modelfield($v,$fields);
            }
        }
        return $list;
    }
    //  字段显示
    function formtext($data){
        $array = array();
        foreach ($data as $k => $v){
            switch($v['formtype']){
                case 'text':
                    $v['formtext'] = '单行文本框';
                    break;
                case 'uptxt':
                    $v['formtext'] = '多附件';
                    break;
                case 'select':
                    $v['formtext'] = '下拉菜单';
                    break;
                case 'radio':
                    $v['formtext'] = '单选框';
                    break;
                case 'upimg':
                    $v['formtext'] = '多图片';
                    break;
                case 'ieedit':
                    $v['formtext'] = '可视化编辑器';
                    break;
                case 'upmv':
                    $v['formtext'] = '多视频';
                    break;
                case 'time':
                    $v['formtext'] = '日期选择框';
                    break;
                case 'textarea':
                    $v['formtext'] = '多行文本框';
                    break;
                case 'upfile':
                    $v['formtext'] = '单文件上传';
                    break;
                case 'updimg':
                    $v['formtext'] = '单图片上传';
                    break;
                case 'checkbox':
                    $v['formtext'] = '多选框';
                    break;
                case 'uppaly':
                    $v['formtext'] = '单视频';
                    break;
                case 'chinacode':
                    $v['formtext'] = '系统地区选择';
                    break;
                case 'shopfile':
                    $v['formtext'] = '自订义属性';
                    break;
                case 'articleaid':
                    $v['formtext'] = '内容调用';
                    break;
                case 'userdatauid':
                    $v['formtext'] = '用户调用';
                    break;
                case 'shopmoney':
                    $v['formtext'] = '多价格选择';
                    break;
                case 'shopsales':
                    $v['formtext'] = '促销活动';
                    break;
            }
            $array[$k] = $v;
        }
        return $array;
    }
    //  生成模型表单
    public function modelfield($data){
        if($data['formrequired'] == 1){
            $required = 'required lay-verify="required"';
            $retext = "(<span class='t-red'>*</span>)";
        }else{
            $required = '';
            $retext = '';
        }
        if(!empty($data['formtitle']) || $data['formtitle'] != null){
            $formtitle = "<div class=\"t-gray\" style=\"width: 100%;clear:both\">{$data['formtitle']}</div>";
        }else{
            $formtitle = '';
        }
        $array = '';
        $array = "<div class=\"x3 t-r\"><label class=\"lab\">{$data['title']}{$retext}</label></div>";
        switch ($data['formtype']){
            case 'text':
                $fl = '';
                if(isset($data['formunist']) && $data['formunist'] != null){
                    $fl = "<div class=\"cx-input-tabel\"><input type=\"text\" name=\"{$data['sqlname']}\" placeholder=\"请输入{$data['title']}\" {$required} class=\"ipt\" value=\"{\$postdb.".$data['sqlname']."|default='".$data['formvalue']."'}\"><span class=\"cx-input-fl\">{$data['formunist']}</span></div>";
                }else{
                    $fl = "<input type=\"text\" name=\"{$data['sqlname']}\" placeholder=\"请输入{$data['title']}\" {$required} class=\"ipt\" value=\"{\$postdb.".$data['sqlname']."|default='".$data['formvalue']."'}\">";
                }
                $array .= "<div class=\"xs8 xl9\">{$fl}{$formtitle}</div>";
                break;
            case 'textarea':
                $array .= "<div class=\"xs8 xl9\"><textarea class=\"ipt\" type=\"text\" name=\"{$data['sqlname']}\" rows=\"3\" {$required}>{\$postdb.".$data['sqlname']."|default='".$data['formvalue']."'}</textarea>{$formtitle}</div>";
                break;
            case 'ieedit':
                $array .= "<div class=\"xs8 xl9\"><div id=\"{$data['sqlname']}\">{\$postdb.".$data['sqlname']."|default='".$data['formvalue']."'}</div><textarea id=\"{$data['sqlname']}txt\" class='hidden' name=\"{$data['sqlname']}\" {$required}>{\$postdb.".$data['sqlname']."|default='".$data['formvalue']."'}</textarea>{$formtitle}</div>
                    <script type=\"text/javascript\">
                        var {$data['sqlname']} = new E('#{$data['sqlname']}');
                        var \${$data['sqlname']}txt = \$('#{$data['sqlname']}txt');
                        {$data['sqlname']}.customConfig.uploadImgServer = \"{:url('Uploads/wangeditor')}\";
                        {$data['sqlname']}.customConfig.uploadImgMaxSize = 1 * 1024 * 1024;
                        {$data['sqlname']}.customConfig.onchange = function (html) {
                            // 监控变化，同步更新到 textarea
                            \${$data['sqlname']}txt.val(html);
                        }
                        {$data['sqlname']}.create();
                        \${$data['sqlname']}txt.val({$data['sqlname']}.txt.html());
                    </script>";
                break;
            case 'radio':
                $value = explode(',',$data['formset']);
                $arr = '';
                foreach ($value as  $v){
                    $arr .= "<input name=\"{$data['sqlname']}\" value=\"{$v}\" {eq name=\"postdb.".$data['sqlname']."|default='".$data['formvalue']."'\" value=\"{$v}\"}checked=\"checked\"{/eq} type=\"radio\" title=\"{$v}\" {$required}>";
                }
                $array .= "<div class=\"xs8 xl9\">{$arr}{$formtitle}</div>";
                break;
            case 'checkbox':
                $value = explode(',',$data['formset']);
                $arr =  '';
                foreach ($value as  $k => $v){
                    $arr .= "<input name=\"{$data['sqlname']}[]\" value=\"{$v}\" {if isset(\$postdb['".$data['sqlname']."']) && in_array('{$v}',explode(',',\$postdb['".$data['sqlname']."']))}checked{/if} type=\"checkbox\" title=\"{$v}\" {$required}>";
                }
                $array .= "<div class=\"xs8 xl9\">{$arr}{$formtitle}</div>";
                break;
            case 'select':
                $value = explode(',',$data['formset']);
                $arr =  "<option value=''>请选择{$data['title']}</option>";
                foreach ($value as  $k => $v){
                    $arr .= "<option value=\"".$v."\" {eq name=\"postdb.{$data['sqlname']}|default='".$data['formvalue']."'\" value=\"".$v."\"}selected=\"selected\"{/eq}>{$v}</option>";
                }
                $array .= "<div class=\"xs8 xl9\"><select id=\"{$data['sqlname']}\" name=\"{$data['sqlname']}\" {$required} lay-filter=\"{$data['sqlname']}\">{$arr}</select>{$formtitle}</div>";
                break;
            case 'time':
                $array .= "<div class=\"xs8 xl9\"><input type=\"text\" name=\"{$data['sqlname']}\" placeholder=\"请选择{$data['title']}\" {$required} class=\"ipt cx-time\" value=\"{\$postdb.".$data['sqlname']."|default='".$data['formvalue']."'}\">{$formtitle}</div>";
                break;
            case 'upfile':
                $array .= "<div class=\"xs8 xl9\"><div class=\"cx-fex-l\"><div class='x6'><input name=\"{$data['sqlname']}\" class=\"ipt {$data['sqlname']}val\" placeholder=\"默认值一般为空\" type=\"text\" value=\"{\$postdb.".$data['sqlname']."|default=''}\" ></div><div><span class=\"{$data['sqlname']}text\"></span><a class=\"button bg-green uploadbtn mr-5\" data-img=\"{$data['sqlname']}img\" data-val=\"{$data['sqlname']}val\" data-text=\"{$data['sqlname']}text\" data-del=\"{$data['sqlname']}del\" lay-data=\"{method:'post',accept:'file',data:'dfile',field:'".$data['sqlname']."'}\"><i class=\"cx-icon cx-icon-shangchuan1\"></i>上传文件</a><a class=\"button bg-red {$data['sqlname']}del cx-click\" data-img=\"{$data['sqlname']}img\" data-val=\"{$data['sqlname']}val\" data-type=\"closdiv\" {notpresent name=\"postdb.".$data['sqlname']."\"}style=\"display:none;\"{/notpresent}><i class=\"cx-icon cx-icon-lajixiang\"></i>删除</a></div></div>{$formtitle}</div>";
                break;
            case 'updimg':
                $array .= "<div class=\"xs8 xl9\"><div class=\"cx-fex-l fex-items-c\"><img class=\"{$data['sqlname']}img\" src=\"{\$postdb.".$data['sqlname']."|default=''}\" alt='' style='max-width:200px;max-height:100px'><input name=\"{$data['sqlname']}\" class=\"ipt {$data['sqlname']}val\" placeholder=\"默认值一般为空\" type=\"hidden\" value=\"{\$postdb.".$data['sqlname']."|default=''}\" ><div class='ml-10'><span class=\"{$data['sqlname']}text\"></span><a class=\"button bg-green uploadbtn mr-5\" data-img=\"{$data['sqlname']}img\" data-val=\"{$data['sqlname']}val\" data-text=\"{$data['sqlname']}text\" data-del=\"{$data['sqlname']}del\" lay-data=\"{method:'post',accept:'file',data:'dfile',field:'".$data['sqlname']."'}\"><i class=\"cx-icon cx-icon-shangchuan1\"></i>上传文件</a><a class=\"button bg-red {$data['sqlname']}del cx-click\" data-img=\"{$data['sqlname']}img\" data-val=\"{$data['sqlname']}val\" data-type=\"closdiv\" {notpresent name=\"postdb.".$data['sqlname']."\"}style=\"display:none;\"{/notpresent}><i class=\"cx-icon cx-icon-lajixiang\"></i>删除</a></div></div>{$formtitle}</div>";
                break;
            case 'upimg':
                $array .= "<div class=\"xs8 xl9\"><div class=\"cx-input-tabel\"><a class=\"button bor-green dfeilds\" data-acc=\"img\" data-tabd=\"{$data['sqlname']}tab\" data-valname=\"{$data['sqlname']}\" lay-data=\"{method:'post',accept:'images',data:'img',field:'".$data['sqlname']."'}\"><i class=\"cx-icon cx-icon-shangchuan1\"></i>选择并上传图片</a></div><div class=\"layui-upload-list\"><table class=\"layui-table\"><thead><tr><th>文件名</th><th class=\"t-c\">状态</th><th class=\"t-c\">大小</th><th class=\"t-c\">操作</th></tr></thead><tbody id=\"{$data['sqlname']}tab\">{volist name=\"postdb.".$data['sqlname']."|default=''\" id=\"cx\"}<tr><td><img src=\"{\$cx.value}\" style='max-width: 200px;max-height: 80px;'><span class=\"up-title\">{\$cx.title}</span><input type=\"hidden\" name=\"{$data['sqlname']}[{\$cx.title}]\" class=\"ipt\" value=\"{\$cx.value}\"></td><td class=\"t-c\"><a class=\"button bg-green\">正常</a></td><td></td><td class=\"t-c\"><a class=\"button bg-red cx-click\" data-type=\"clostr\">删除</a></td></tr>{/volist}</tbody></table></div>{$formtitle}</div>";
                break;
            case 'uptxt':
                $array .= "<div class=\"xs8 xl9\"><div class=\"cx-input-tabel\"><a class=\"button bor-green dfeilds\" data-acc=\"dfile\" data-tabd=\"{$data['sqlname']}tab\" data-valname=\"{$data['sqlname']}\" lay-data=\"{method:'post',accept:'file',data:'dfile',field:'".$data['sqlname']."'}\"><i class=\"cx-icon cx-icon-shangchuan1\"></i>选择并上传文件</a></div><div class=\"layui-upload-list\"><table class=\"layui-table\"><thead><tr><th>文件名</th><th class=\"t-c\">状态</th><th class=\"t-c\">大小</th><th class=\"t-c\">操作</th></tr></thead><tbody id=\"{$data['sqlname']}tab\">{volist name=\"postdb.".$data['sqlname']."|default=''\" id=\"cx\"}<tr><td>{\$cx.title}<input type=\"hidden\" name=\"{$data['sqlname']}[{\$cx.title}]\" class=\"ipt\" value=\"{\$cx.value}\"></td><td class=\"t-c\"><a class=\"button bg-green\">正常</a></td><td></td><td class=\"t-c\"><a class=\"button bg-red cx-click\" data-type=\"clostr\">删除</a></td></tr>{/volist}</tbody></table>{$formtitle}</div></div>";
                break;
            case 'upmv':
                $array .= "<div class=\"xs8 xl9\"><div class=\"cx-input-tabel\"><a class=\"button bor-green dfeilds\" data-acc=\"dfile\" data-tabd=\"{$data['sqlname']}tab\" data-valname=\"{$data['sqlname']}\" lay-data=\"{method:'post',accept:'video',data:'dfile',field:'".$data['sqlname']."'}\"><i class=\"cx-icon cx-icon-shangchuan1\"></i>选择并上传视频</a></div><div class=\"layui-upload-list\"><table class=\"layui-table\"><thead><tr><th>文件名</th><th class=\"t-c\">状态</th><th class=\"t-c\">大小</th><th class=\"t-c\">操作</th></tr></thead><tbody id=\"{$data['sqlname']}tab\">{volist name=\"postdb.".$data['sqlname']."|default=''\" id=\"cx\"}<tr><td>{\$cx.title}<input type=\"hidden\" name=\"{$data['sqlname']}[{\$cx.title}]\" class=\"ipt\" value=\"{\$cx.value}\"></td><td class=\"t-c\"><a class=\"button bg-green\">正常</a></td><td></td><td class=\"t-c\"><a class=\"button bg-red cx-click\" data-type=\"clostr\">删除</a></td></tr>{/volist}</tbody></table></div></div>";
                break;
            case 'uppaly':
                $array .= "<div class=\"xs8 xl9\"><div class=\"cx-fex-l\"><div class='x6'><input name=\"{$data['sqlname']}\" class=\"ipt {$data['sqlname']}val\" placeholder=\"默认值一般为空\" type=\"text\" value=\"{\$postdb.".$data['sqlname']."|default=''}\" ></div><div><span class=\"{$data['sqlname']}text\"></span><a class=\"button bg-green uploadbtn\" data-img=\"{$data['sqlname']}img\" data-val=\"{$data['sqlname']}val\" data-text=\"{$data['sqlname']}text\" data-del=\"{$data['sqlname']}del\" lay-data=\"{method:'post',accept:'video',data:'dfile',field:'".$data['sqlname']."'}\"><i class=\"cx-icon cx-icon-shangchuan1\"></i>上传视频文件</a><a class=\"button bg-red {$data['sqlname']}del cx-click\" data-img=\"{$data['sqlname']}img\" data-val=\"{$data['sqlname']}val\" data-type=\"closdiv\" {notpresent name=\"postdb.".$data['sqlname']."\"}style=\"display:none;\"{/notpresent}><i class=\"cx-icon cx-icon-lajixiang\"></i>删除</a></div></div></div>";
                break;
            case 'chinacode':
                $sheng = '';
                $china = model('Chinacode')->get_don();
                $sheng = "<option value=\"\">请选择省</option>";
                //  获取省份
                foreach ($china as $v){
                    $sheng .= "<option value=\"{$v['zoneid']}\">{$v['zonename']}</option>";
                }
                $select = "{notempty name=\"postdb.".$data['sqlname']."\"}{volist name=\"postdb.".$data['sqlname']."\" id=\"cx\" key=\"k\"}<select class='{$data['sqlname']}' name=\"{$data['sqlname']}[{\$k}]\" lay-filter=\"chinacode\" data-th='{\$cx}' data-leve='{\$k}' data-name='{$data['sqlname']}' data-class='don'></select>{/volist}
<script> $('.{$data['sqlname']}').each(function () { var o = this,d = $(o).data();if(d.leve == 1){ var x = '省份';} if(d.leve == 2){ var x = '市';} if(d.leve == 3){ var x = '县/区';} if(d.leve == 4){ var x = \"乡/镇/街道\";} $.ajax({ async:false,type: \"post\", dataType: \"json\", data: {zoneid:d.th,class:'this',type:'num'}, url: \"/api/chinacode.html\", success:function (res) { if(res.code == '1'){ var sele = res.dondata; $(o).html(\"<option value=''>请选择\"+ x +\"</option>\"); for(var i in sele){ if(d.th == sele[i].zoneid){ $(o).append(\"<option value='\"+sele[i].zoneid+\"'selected='selected'>\"+sele[i].zonename+\"</option>\"); }else{ $(o).append(\"<option value='\"+sele[i].zoneid+\"'>\"+sele[i].zonename+\"</option>\"); }}}}});})</script>{else /}
<select class='{$data['sqlname']}' name=\"{$data['sqlname']}[1]\" lay-filter=\"chinacode\" data-leve='1' data-name='{$data['sqlname']}' data-class='don' data-type='num'>{$sheng}</select>{/notempty}";
                $array .= "<div class=\"xs8 xl9\"><div class=\"cx-input-tabel\">{$select}</div></div>";
                break;
            case 'articleaid':
                if($data['formsetrad'] == '0'){
                    $inputclass = "{present name=\"postdb.".$data['sqlname']."\"}<div class='x3 mr-5 mb-5 fex-column' style='border: 1px solid #dfdfdf;padding: 5px'><img class='img-responsive' src='{\$postdb.{$data['sqlname']}.picurl}' alt=''><div class='layout t-c'><input type='radio' checked='checked' name='{$data['sqlname']}' value='{\$postdb.{$data['sqlname']}.aid}' title='{\$postdb.{$data['sqlname']}.title}' lay-skin='primary'></div></div>{/present}";
                    $inputclassjs = "<div class='x3 mr-5 mb-5 fex-column' style='border: 1px solid #dfdfdf;padding: 5px'><img class='img-responsive' src='\"+this.picurl+\"' alt=''><div class='layout t-c'><input type='radio' name='{$data['sqlname']}' value='\"+this.aid+\"' title='\"+ this.title +\"' lay-skin='primary'></div></div>";
                }else{
                    $inputclass = "{present name=\"postdb.".$data['sqlname']."\"}{volist name=\"postdb.{$data['sqlname']}\" id=\"cx\" empty=\"\"}<div class='x3 mr-5 mb-5 fex-column' style='border: 1px solid #dfdfdf;padding: 5px'><img class='img-responsive' src='{\$cx.picurl}' alt=''><div class='layout t-c'><input type='checkbox' checked='checked' name='{$data['sqlname']}[]' value='{\$cx.aid}' title='{\$cx.title}' lay-skin='primary'></div></div>{/volist}{/present}";
                    $inputclassjs = "<div class='x3 mr-5 mb-5 fex-column' style='border: 1px solid #dfdfdf;padding: 5px'><img class='img-responsive' src='\"+this.picurl+\"' alt=''><div class='layout t-c'><input type='checkbox' name='{$data['sqlname']}[]' value='\"+this.aid+\"' title='\"+ this.title +\"' lay-skin='primary'></div></div>";
                }

                $array .= "<div class=\"xs8 xl9\">
<div class=\"x6 cx-input-tabel\"><input id=\"{$data['sqlname']}\" placeholder=\"请输入{$data['title']}关键词\" class=\"ipt\" value=\"\" type=\"text\"><span class=\"button bg-yellow cx-input-fl\" onclick=\"so{$data['sqlname']}(this)\" data-cid=\"{$data['sqlname']}\">搜索{$data['title']}</span></div><div class=\"{$data['sqlname']} mt-10 cx-fex-l\">{$inputclass}</div></div><script>function so{$data['sqlname']}(o){var d = $(o).data(),dv = $(\"#\"+d.cid).val();if(!dv.length){layer.msg(\"请输入{$data['title']}关键词\");return false;}$.ajax({async:false,type: \"post\",dataType: \"json\",data: {k:dv,m:[{$data['formset']}]},url: \"{:url('Article/get_aid')}\",success:function (data) {if(data != '0'){ $('{$data['sqlname']}').html('');$(data).each(function () { $('.{$data['sqlname']}').append(\"{$inputclassjs}\");});layui.use('form', function() {var form = layui.form;form.render();});}}})}</script>";
                break;
            case 'userdatauid':
                if($data['formsetrad'] == '0'){
                    $inputclass = "{present name=\"postdb.".$data['sqlname'].".uid\"}<input type='radio' checked='checked' name='{$data['sqlname']}' value='{\$postdb.{$data['sqlname']}.uid}' title='会员名: {\$postdb.{$data['sqlname']}.username} 会员昵称: {\$postdb.{$data['sqlname']}.uniname}'>{/present}";
                    $inputclassjs = "<input type='radio' name='{$data['sqlname']}' value='\" + this.uid + \"' title='会员名 \" + this.username + \" 会员昵称: \" + this.uniname + \"' lay-skin='primary'>";
                }else{
                    $inputclass = "{present name=\"postdb.".$data['sqlname']."\"}{volist name=\"postdb.{$data['sqlname']}\" id=\"cx\" empty=\"\"}<input type='checkbox' checked='checked' name='{$data['sqlname']}[]' value='{\$cx.uid}' title='会员名: {\$cx.username}  会员昵称:{\$cx.uniname}' lay-skin='primary'>{/volist}{/present}";
                    $inputclassjs = "<input type='checkbox' name='{$data['sqlname']}[]' value='\" + this.uid + \"' title='会员名 \" + this.username + \" 会员昵称: \" + this.uniname + \"' lay-skin='primary'>";
                }
                $array .= "<div class=\"xs8 xl9\"><div class=\"x6 cx-input-tabel\"><input id=\"{$data['sqlname']}\" placeholder=\"请输入用户名或昵称\" class=\"ipt\" value=\"\" type=\"text\"><span class=\"button bg-yellow cx-input-fl\" onclick=\"so{$data['sqlname']}(this)\" data-cid=\"{$data['sqlname']}\">搜索{$data['title']}</span></div><div class=\"{$data['sqlname']} mt-10 cx-fex-l\"><div class='mr-5 mb-5' style='border: 1px solid #dfdfdf;padding: 5px'> {$inputclass} </div></div></div><script>function so{$data['sqlname']}(o){ var d = $(o).data(),dv = $(\"#\"+d.cid).val();if(!dv.length > 1){ layer.msg(\"请输入用户名或昵称\");return false;} $.ajax({ async:false,type: \"post\",dataType: \"json\",data: { k:dv,m:'{$data['formset']}' },url: \"{:url('UserData/get_uid')}\",success:function (data) { if(data != '0'){ $('.{$data['sqlname']}').html('');$(data).each(function () {  $('.{$data['sqlname']}').append(\"<div class='mr-5 mb-5' style='border: 1px solid #dfdfdf;padding: 5px'> {$inputclassjs} </div>\"); });layui.use('form', function() { var form = layui.form;form.render();});}}})}</script>";
                break;
            case 'shopfile':
                $arr = $fl = $jsfl = '';
                if(isset($data['formunist']) && $data['formunist'] != null){
                    $fl = "<div class=\"cx-input-tabel\"><input name=\"{$data['sqlname']}[{\$k}][value]\" class=\"ipt\" value=\"{\$cx.value}\" type=\"text\"><span class=\"cx-input-fl\">{$data['formunist']}</span></div>";
                    $jsfl = "<div class=\\\"cx-input-tabel\\\"><input name=\\\"{$data['sqlname']}[\"+n+\"][value]\\\" class=\\\"ipt\\\" value=\\\"\\\" type=\\\"text\\\" placeholder=\\\"请输入{$data['title']}属性\\\"><span class=\\\"cx-input-fl\\\">{$data['formunist']}</span></div>";
                }else{
                    $fl = "<input name=\"{$data['sqlname']}[{\$k}][value]\" class=\"ipt\" value=\"{\$cx.value}\" type=\"text\">";
                    $jsfl = "<input name=\\\"{$data['sqlname']}[\"+n+\"][value]\\\" class=\\\"ipt\\\" value=\\\"\\\" type=\\\"text\\\" placeholder=\\\"请输入{$data['title']}属性\\\">";
                }
                $array .= "<div class=\"xs8 xl9\"><span class=\"button bor-green mb-10\" onclick=\"add{$data['sqlname']}(this)\">添加{$data['title']}</span><div class=\"layout cx-{$data['sqlname']}conf\">{present name=\"postdb.".$data['sqlname']."\"}{volist name=\"postdb.".$data['sqlname']."\" id=\"cx\" key=\"k\"}<div class=\"layout cx-fex-l {$data['sqlname']}num {$data['sqlname']}-{\$k} mb-10\" data-nums=\"{\$k}\"><div class=\"x3 mr-5\"><input name=\"{$data['sqlname']}[{\$k}][title]\" class=\"ipt\" value=\"{\$cx.title}\" type=\"text\"></div><div class=\"x6 mr-5\">{$fl}</div><span class=\"button bg-red cx-click\" data-type=\"delclass\" data-cid=\"{$data['sqlname']}-{\$k}\">删除{$data['title']}</span></div>{/volist}{/present}</div>{$formtitle}</div><script>function add{$data['sqlname']}(o) {var n = $('.cx-{$data['sqlname']}conf').children().length;if(n > 0){n = $('.cx-{$data['sqlname']}conf').children('.{$data['sqlname']}num:last').data('nums');}n = n + 1;var dv = \"<div class=\\\"layout cx-fex-l {$data['sqlname']}num {$data['sqlname']}-\"+n+\" mb-10\\\" data-nums=\\\"\"+n+\"\\\"><div class=\\\"x3 mr-5\\\" ><input name=\\\"{$data['sqlname']}[\"+n+\"][title]\\\" class=\\\"ipt\\\" placeholder=\\\"请输入{$data['title']}名\\\" value=\\\"\\\" type=\\\"text\\\" ></div ><div class=\\\"x6 mr-5\\\" >{$jsfl}</div> <span class=\\\"button bg-red cx-click\\\" data-type=\\\"delclass\\\" data-cid=\\\"{$data['sqlname']}-\"+n+\"\\\" > 删除{$data['title']}</span ></div >\";$('.cx-{$data['sqlname']}conf').append(dv);}</script>";
                break;
            case 'shopsales':
                $arr = $fl = $jsfl = '';
                if(isset($data['formunist']) && $data['formunist'] != null){
                    $fl = "<div class=\"cx-input-tabel\"><input name=\"{$data['sqlname']}[{\$k}][value]\" class=\"ipt\" value=\"{\$cx.value}\" type=\"text\"><span class=\"cx-input-fl\">{$data['formunist']}</span></div>";
                    $jsfl = "<div class=\\\"cx-input-tabel\\\"><input name=\\\"{$data['sqlname']}[\"+n+\"][value]\\\" class=\\\"ipt\\\" value=\\\"\\\" type=\\\"text\\\" placeholder=\\\"请输入{$data['title']}属性\\\"><span class=\\\"cx-input-fl\\\">{$data['formunist']}</span></div>";
                }else{
                    $fl = "<input name=\"{$data['sqlname']}[{\$k}][value]\" class=\"ipt\" value=\"{\$cx.value}\" type=\"text\">";
                    $jsfl = "<input name=\\\"{$data['sqlname']}[\"+n+\"][value]\\\" class=\\\"ipt\\\" value=\\\"\\\" type=\\\"text\\\" placeholder=\\\"请输入{$data['title']}属性\\\">";
                }
                $array .= "<div class=\"xs8 xl9\"><span class=\"button bor-green mb-10\" onclick=\"add{$data['sqlname']}(this)\">添加{$data['title']}</span><div class=\"layout cx-{$data['sqlname']}conf\">{present name=\"postdb.".$data['sqlname']."\"}{volist name=\"postdb.".$data['sqlname']."\" id=\"cx\" key=\"k\"}<div class=\"layout cx-fex-l {$data['sqlname']}num {$data['sqlname']}-{\$k} mb-10\" data-nums=\"{\$k}\"><div class=\"x3 mr-5\"><input name=\"{$data['sqlname']}[{\$k}][title]\" class=\"ipt\" value=\"{\$cx.title}\" type=\"text\"></div><div class=\"x6 mr-5\">{$fl}</div><span class=\"button bg-red cx-click\" data-type=\"delclass\" data-cid=\"{$data['sqlname']}-{\$k}\">删除{$data['title']}</span></div>{/volist}{/present}</div>{$formtitle}</div><script>function add{$data['sqlname']}(o) {var n = $('.cx-{$data['sqlname']}conf').children().length;if(n > 0){n = $('.cx-{$data['sqlname']}conf').children('.{$data['sqlname']}num:last').data('nums');}n = n + 1;var dv = \"<div class=\\\"layout cx-fex-l {$data['sqlname']}num {$data['sqlname']}-\"+n+\" mb-10\\\" data-nums=\\\"\"+n+\"\\\"><div class=\\\"x3 mr-5\\\" ><input name=\\\"{$data['sqlname']}[\"+n+\"][title]\\\" class=\\\"ipt\\\" placeholder=\\\"请输入{$data['title']}名\\\" value=\\\"\\\" type=\\\"text\\\" ></div ><div class=\\\"x6 mr-5\\\" >{$jsfl}</div> <span class=\\\"button bg-red cx-click\\\" data-type=\\\"delclass\\\" data-cid=\\\"{$data['sqlname']}-\"+n+\"\\\" > 删除{$data['title']}</span ></div >\";$('.cx-{$data['sqlname']}conf').append(dv);}</script>";
                break;
            case 'shopmoney':
                $arr = '';
                $array .= "<div class=\"xs8 xl9\"><div class=\"layout cx-{$data['sqlname']}conf\">{present name=\"postdb.".$data['sqlname']."\"}{volist name=\"postdb.".$data['sqlname']."\" id=\"cx\" key=\"k\"}<div class=\"layout cx-fex-l {$data['sqlname']}num {$data['sqlname']}-{\$k} mb-10\" data-nums=\"{\$k}\"><div class=\"x3 mr-5\"><input name=\"{$data['sqlname']}[{\$k}][title]\" class=\"ipt\" value=\"{\$cx.title}\" type=\"text\"></div><div class=\"x6\"><div class=\"cx-input-tabel\"><input name=\"{$data['sqlname']}[{\$k}][value]\" class=\"ipt\" value=\"{\$cx.value}\" type=\"text\"><span class=\"cx-input-fl\">元</span></div></div><span class=\"button bg-red ml-10 cx-click\" data-type=\"delclass\" data-cid=\"{$data['sqlname']}-{\$k}\">删除价格</span></div>{/volist}{/present}</div><span class=\"button bor-green\" onclick=\"add{$data['sqlname']}(this)\">请输入自订义价格</span></div><script>function add{$data['sqlname']}(o) { var n = $('.cx-{$data['sqlname']}conf').children().length;if(n > 0){ n = $('.cx-{$data['sqlname']}conf').children('.{$data['sqlname']}num:last').data('nums');} n = n + 1; var dv = \"<div class=\\\"layout cx-fex-l {$data['sqlname']}num {$data['sqlname']}-\"+n+\" mb-10\\\" data-nums=\\\"\"+n+\"\\\"><div class=\\\"x3 mr-5\\\" ><input name=\\\"{$data['sqlname']}[\"+n+\"][title]\\\" class=\\\"ipt\\\" placeholder=\\\"请输入自订义规格\\\" value=\\\"\\\" type=\\\"text\\\" ></div ><div class=\\\"x6\\\" ><div class=\\\"cx-input-tabel\\\" ><input name=\\\"{$data['sqlname']}[\"+n+\"][value]\\\" class=\\\"ipt\\\" value=\\\"\\\" type=\\\"text\\\" placeholder=\\\"请输入自订义价格\\\"><span class=\\\"cx-input-fl\\\">元</span></div></div> <span class=\\\"button bg-red ml-10 cx-click\\\" data-type=\\\"delclass\\\" data-cid=\\\"{$data['sqlname']}-\"+n+\"\\\" > 删除价格</span ></div >\"; $('.cx-{$data['sqlname']}conf').append(dv);}</script>";
                break;
        }
        $array = "<div class=\"cx-fex-l mb-10\">{$array}</div>";
        return $array;
    }
    //  生成模型表单
    public function modelth($data){
        $art = '';
        if(!empty($data['listsee']) && isset($data['listsee']) && $data['listsee'] == '1'){
            $art =  "<th class='t-c'>{$data['title']}</th>";
        }
        return $art;
    }
    //  生成模型表单
    public function modeltd($data){
        $art = '';
        if(!empty($data['listsee']) && isset($data['listsee']) && $data['listsee'] == '1'){
            $art =  "<td class='t-c'>{\$cx.{$data['sqlname']}}</td>";
        }
        return $art;
    }
    //  生成内容页面
    public function modelarticle($data){
        $array = $formunist = '';
        if($data['formtype'] == 'upimg'){
            $art = "{volist name=\"\$postdb.{$data['sqlname']}\" id=\"c\" empty=\"\"}<img src='{\$c.value}'>{/volist}";
        }elseif($data['formtype'] == 'uptxt' || $data['formtype'] == 'upmv'){
            $art = "{volist name=\"\$postdb.{$data['sqlname']}\" id=\"c\" empty=\"\"}{\$c.value}{/volist}";
        }else{
            $art = "{\$postdb.{$data['sqlname']}}";
        }
        if(isset($data['formunist']) && $data['formunist'] != null){
            $formunist = $data['formunist'];
        }
        $array = "<div class=\"cx-fex-l mb-10\">
                        <div class=\"x3 t-r\">
                         <label class=\"lab\">{$data['title']}</label>
                         </div>
                        <div class=\"xs8 xl9\">
                             <label class=\"lab t-red\">{$art} {$formunist}</label>
                        </div>
                    </div>";
        return $array;
    }
    //  读取文件
    public function file_read($filename,$method="rb"){
        if($handle=@fopen($filename,$method)){
            @flock($handle,LOCK_SH);
            $filedata=@fread($handle,@filesize($filename));
            @fclose($handle);
        }
        return $filedata;
    }
    //  写入文件
    public function file_write($filename,$data,$metd='rb+',$flock='1'){
        @touch($filename);
        $op = @fopen($filename,$metd);
        if($flock){
            @flock($op,LOCK_EX);
        }
        @fputs($op,$data);
        if($metd=="rb+"){
            @ftruncate($op,strlen($data));
        }
        @fclose($op);
        @chmod($filename,0777);
        if(is_writable($filename) ){
            return 1;
        }else{
            return 0;
        }
    }
}
